package com.reebake.ideal.user.controller;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.reebake.ideal.mybatis.core.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.reebake.ideal.user.entity.UserThirdParty;
import com.reebake.ideal.user.service.UserThirdPartyService;
import com.reebake.ideal.user.vo.UserThirdPartyQueryParamVO;
import com.reebake.ideal.user.vo.UserThirdPartyVO;

 /**
 * 三方用户控制层
 */
@Tag(name = "三方用户对象功能接口")
@RestController
@RequestMapping("/user/third/party")
public class UserThirdPartyController {
    @Autowired
    private UserThirdPartyService userThirdPartyService;
    
    /** 
     * 分页查询
     *
     * @param queryParam 查询参数
     * @return 查询结果
     */
    @Operation(summary = "分页查询")
    @PostMapping("page")
    public PageResult<UserThirdPartyVO> page(@RequestBody UserThirdPartyQueryParamVO queryParam) {
        LambdaQueryWrapper<UserThirdParty> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StrUtil.isNotBlank(queryParam.getUserId()), UserThirdParty::getUserId, queryParam.getUserId());
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getUuid()), UserThirdParty::getUuid, queryParam.getUuid());
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getUsername()), UserThirdParty::getUsername, queryParam.getUsername());
        
        queryParam = userThirdPartyService.page(queryParam, queryWrapper);
        
        return queryParam.to(UserThirdPartyVO.class);
    }
    
    /** 
     * 保存或更新数据
     *
     * @param userThirdParty 实例对象
     */
    @Operation(summary = "保存或更新数据")
    @PostMapping("save")
    public void save(@RequestBody UserThirdPartyVO userThirdParty) {
        userThirdPartyService.saveOrUpdate(BeanUtil.copyProperties(userThirdParty, UserThirdParty.class));
    }
    
    /** 
     * 通过主键批量删除
     *
     * @param userThirdPartyIds 主键
     */
    @Operation(summary = "通过主键批量删除")
    @PostMapping("remove-by-ids")
    public void removeByIds(@RequestBody List<String> userThirdPartyIds) {
        userThirdPartyService.removeByIds(userThirdPartyIds);
    }
}